#include <iostream>
#include <string>
#include <winsock.h>
#pragma comment(lib, "wsock32.lib")
int main()
{
  struct ForSend //structure for sending data to the server
  {
      short family;
      unsigned short port;
      struct in_addr addr;
      int choise;
      char *ReturnAddr;
  };
  int choise;
  WSAData WSData;
  WSAStartup(0x202,&WSData);
  SOCKET CreateClient = socket(AF_INET,SOCK_STREAM,0);
  ForSend Client;
  Client.family=AF_INET;
  Client.port=htons(3135);
  Client.addr.S_un.S_addr=inet_addr("127.0.0.1");
  connect(CreateClient,(sockaddr*)&Client,sizeof(Client));
  char buf[128];
  hostent *h;
  if (!WSAStartup(0x202, &WSData)) 
  {
      if (gethostname(buf, 128) == 0)
      {
           h = gethostbyname(buf);
           Client.ReturnAddr=(*(h->h_addr_list));//get ip
      }
  }
  std::cout<<"Hello"<<"\n"<<"What do you want? \n1.Share file's \n2.Download file's \n3.Exit program \nPlease insert you choise: ";
  std::cin>>choise;
  while(1)
  {
    if(choise==1)
    {
        std::cout<<"What file you want to share?\nEnter the name: ";
        std::string NameFileShare;
        std::cin>>NameFileShare;   
        Client.choise=1;
        send(CreateClient,NameFileShare.c_str(),NameFileShare.length(),0);
    }
    else if(choise==2)
    {
        std::cout<<"What file you want download?\nEnter the name: ";
        std::string NameFileDowload;
        std::cin>>NameFileDowload;
        Client.choise=2;
        send(CreateClient,NameFileDowload.c_str(),NameFileDowload.length(),0);
    }
    else if(choise==3){break;}
    else {std::cout<<"Incorrect input\n";}
  }
  closesocket(CreateClient);
  return 0;
}
